﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:Button="clr-namespace:myManga_App.Resources.Theme.Buttons"
    xmlns:Converters="clr-namespace:myManga_App.Converters"
    xmlns:Objects="clr-namespace:myManga_App.Objects"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    x:Class="myManga_App.Views.SettingsView"
    mc:Ignorable="d" 
    d:DesignHeight="400"
    d:DesignWidth="600">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/myManga;component/Themes/ScrollBar/ScrollBar.xaml"/>
                <ResourceDictionary Source="/myManga;component/Themes/ListBox/ListBoxItems.xaml"/>
                <ResourceDictionary Source="/myManga;component/Themes/Slider/Slider.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <Converters:CommandParameterStringFormat x:Key="CommandParameterStringFormat"/>
            <Converters:EnumToBooleanConverter x:Key="EnumToBooleanConverter"/>
            <GridLength x:Key="SettingNameColumnWidth">200</GridLength>
            <System:Double x:Key="SettingNameFontSize">20</System:Double>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid Background="{DynamicResource window-background}">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <ScrollViewer>
            <StackPanel>
                <Grid Margin="0,3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="{StaticResource SettingNameColumnWidth}"/>
                        <ColumnDefinition Width="15"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Site Extentions" VerticalAlignment="Top" TextWrapping="Wrap" FontSize="{StaticResource SettingNameFontSize}"/>
                    <ListBox
                        Grid.Column="2"
				        Background="{DynamicResource window-background}"
                        ItemContainerStyle="{DynamicResource SettingsView_SiteExtensionInformationObjectListBoxItem}"
				        ItemsSource="{Binding SiteExtensionInformationObjects}"
				        HorizontalContentAlignment="Stretch"/>
                </Grid>
                <Grid Margin="0,3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="{StaticResource SettingNameColumnWidth}"/>
                        <ColumnDefinition Width="15"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Database Extentions" VerticalAlignment="Top" TextWrapping="Wrap" FontSize="{StaticResource SettingNameFontSize}"/>
                    <ListBox
                        Grid.Column="2"
					    Background="{DynamicResource window-background}"
                        ItemContainerStyle="{DynamicResource SettingsView_DatabaseExtensionInformationObjectListBoxItem}"
					    ItemsSource="{Binding DatabaseExtensionInformationObjects}"
					    HorizontalContentAlignment="Stretch"/>
                </Grid>
                <Grid Margin="0,3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="{StaticResource SettingNameColumnWidth}"/>
                        <ColumnDefinition Width="15"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Storage Serialization" VerticalAlignment="Center" TextWrapping="Wrap" FontSize="{StaticResource SettingNameFontSize}"/>
                    <ComboBox
                        Grid.Column="2"
                        ItemsSource="{Binding SaveTypes}"
                        SelectedItem="{Binding SelectedSaveType}"/>
                </Grid>
                <Grid Margin="0,3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="{StaticResource SettingNameColumnWidth}"/>
                        <ColumnDefinition Width="15"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock
                        TextWrapping="Wrap"
                        FontSize="{StaticResource SettingNameFontSize}"
                        Text="{Binding Value, ElementName=DefaultPageZoomSlider, StringFormat=Default\ Zoom\ Amount:\ {0:0.0}x}"
                        VerticalAlignment="Center"/>
                    <Slider
                        x:Name="DefaultPageZoomSlider"
                        Grid.Column="2"
                        Orientation="Horizontal"
                        Minimum="0.5"
                        Maximum="2"
                        Value="{Binding Path=DefaultPageZoom, Mode=TwoWay, FallbackValue=1}" 
                        TickPlacement="BottomRight"
                        TickFrequency="0.1"
                        LargeChange="0.5" 
                        SmallChange="0.1" 
                        IsMoveToPointEnabled="True" 
                        IsSnapToTickEnabled="True"/>
                </Grid>
                <Grid Margin="0,3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="{StaticResource SettingNameColumnWidth}"/>
                        <ColumnDefinition Width="15"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Clean Chapters" VerticalAlignment="Center" TextWrapping="Wrap" FontSize="{StaticResource SettingNameFontSize}"/>
                    <Button:MetroToggleButton
                        Grid.Column="2"
                        x:Name="RemoveBackChaptersToggleButton"
                        HorizontalAlignment="Right"
                        Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
                        IsChecked="{Binding RemoveBackChapters, Mode=TwoWay}" 
                        FontFamily="{DynamicResource OpenIconic}"
                        Content="{DynamicResource oi-check}"/>
                </Grid>
                <Grid Margin="0,3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="{StaticResource SettingNameColumnWidth}"/>
                        <ColumnDefinition Width="15"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock 
                        Text="{Binding Value, ElementName=BackChaptersToKeepSlider, StringFormat=Chapters\ to\ Clean:\ {0:0}}"
                        VerticalAlignment="Center" 
                        TextWrapping="Wrap" 
                        FontSize="{StaticResource SettingNameFontSize}"/>
                    <Slider
                        Grid.Column="2"
                        x:Name="BackChaptersToKeepSlider"
                        Value="{Binding BackChaptersToKeep, FallbackValue=3}"
                        Minimum="2" Maximum="20"/>
                </Grid>
                <StackPanel 
                    Orientation="Horizontal" 
                    TextElement.FontSize="{StaticResource SettingNameFontSize}"
                    TextElement.Foreground="{DynamicResource text-dark}">
                    <TextBlock Text="Theme:" Margin="0,0,5,0"/>
                    <RadioButton 
                        Margin="0,0,5,0"
                        GroupName="Theme" 
                        VerticalContentAlignment="Center"
                        IsChecked="{Binding Path=Theme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static Objects:ThemeType.Light}}">
                        <TextBlock Text="Light" Foreground="{DynamicResource text-dark}"/>
                    </RadioButton>
                    <RadioButton 
                        Margin="0,0,5,0"
                        GroupName="Theme" 
                        VerticalContentAlignment="Center"
                        IsChecked="{Binding Path=Theme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static Objects:ThemeType.Dark}}">
                        <TextBlock Text="Dark" Foreground="{DynamicResource text-dark}"/>
                    </RadioButton>
                </StackPanel>
            </StackPanel>
        </ScrollViewer>
        <StackPanel
			HorizontalAlignment="Right"
			Grid.Column="2"
			Grid.Row="1"
			Orientation="Horizontal"
			TextElement.FontSize="20"
			TextElement.FontFamily="{DynamicResource FontAwesome}">
            <Button:MetroButton                
				Content="{StaticResource fa-save}"
				ContentStringFormat="{}{0} Save"
				Command="{Binding SaveCommand}"/>
            <Button:MetroButton
				Content="{StaticResource fa-times}"
				ContentStringFormat="{}{0} Close"
				Command="{Binding CloseCommand}"/>
        </StackPanel>
    </Grid>
</UserControl>
